package com.zzc.fwzpxt.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zzc.fwzpxt.entity.RegCapital;
import com.zzc.fwzpxt.entity.RegDate;
import com.zzc.fwzpxt.service.IRegDateService;
import com.zzc.common.controller.BaseController;
import com.zzc.common.result.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 * 注册时间-年 reg_date 前端控制器
 * </p>
 *
 * @author XiaoBingBy
 * @since 2017-09-26
 */
@Controller
@RequestMapping("/admin/regDate")
public class RegDateController extends BaseController {

    @Autowired
    private IRegDateService iRegDateService;

    @GetMapping("/list")
    public String list() {
        return blogPath + "reg_date/list";
    }


    @ResponseBody
    @RequestMapping("/getList")
    public List<RegDate> getList() {
        EntityWrapper<RegDate> wrapper = new EntityWrapper<>();
        wrapper.eq("status", 1);
        wrapper.orderBy("reg_date_year", true);
        List<RegDate> regDate = iRegDateService.selectList(wrapper);
        return regDate;
    }

    /**
     * 添加修改
     * @param regDate
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/save")
    public JsonResult save(RegDate regDate) {
        if (regDate.getId() == null) {
            return iRegDateService.insert(regDate) ? renderSuccess("添加成功") : renderError("添加失败");
        } else {
            return iRegDateService.updateById(regDate) ? renderSuccess("修改成功") : renderError("修改失败");
        }
    }

}
